package chetan.TodoList;


import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class Todolist extends Activity implements OnKeyListener {
	ArrayAdapter<String> mAdapter;
	ListView mListView;
	EditText mEditText;
    /** Called when the activity is first created. */
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	//inflate the view
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //create the subviews
        mListView = (ListView) findViewById(R.id.listView1);
        mEditText = (EditText) findViewById(R.id.editText1);
        
        //create an array list of todo items
        mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
        
        //add this array to the list view
        mListView.setAdapter(mAdapter);
        
        mEditText.setOnKeyListener(this);
    }

	@Override
	public boolean onKey(View v, int keyCode, KeyEvent event) {
		if (event.getAction() == KeyEvent.ACTION_DOWN){
			switch (keyCode){
			case KeyEvent.KEYCODE_DPAD_CENTER:
			case KeyEvent.KEYCODE_ENTER:
				mAdapter.add(mEditText.getText().toString());
				mEditText.setText("");
				return true;
				}
		}
		return false;
	}
}